home *** CD-ROM | disk | FTP | other *** search
- Path: beach.and.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: What's your compiler's answer?
- Date: 7 Feb 1996 17:39:29 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4fao4h$dn8@beach.and.nl>
- References: <1996Feb7.140945.28351@cs.rit.edu>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <1996Feb7.140945.28351@cs.rit.edu>, kar@cs.rit.edu wrote:
-
- | In preparing some materials for a course, I wrote the following
- |program to illustrate that the order of expression evaluation is not
- |determined completely by the precedence of the operators involved. I
- |ran it on every compiler I could find and, not surprisingly, got lots of
- |different answers.
-
- | int main(){
- | int i = 10;
- |
- | i = i-- - --i * ( i = -3 ) * i++ + ++i;
- | printf( "i = %d\n", i );
- | return 0;
- | }
- |
- |Results found to date:
- |
- |21 Borland C/C++ 4.0, Turbo C++ 4.5
- |-86 Sun 3/50 cc
- |-85 Sun Sparc cc, SunOS 4.1.4 (a K&R compiler)
- |4 Sun Sparc acc, SunOS 4.1.4 (an ANSI compiler)
- |36 DEC VAX/VMS
- |21 Silicon Graphics Indy, IRIX 5.3
- |-63 gcc 2.6.3
-
- Here are some more results:
-
- "biff" gcc 2.4.1 (after sunset)
- 1/0 xlc AIX 4 (after typing it all in single-handed on the 2nd SP/2 node)
- NaN xlc AIX 4 (running the same thingy again ..)
-
- No seriously, you shouldn't present this example at all, because the
- behavior of that expression is undefined. One single object 'i' is
- altered more than once between two sequence points, so anything can
- happen. And this 'anything' doesn't happen because of a lack of
- complete determination of operator precedence ...
-
- kind regards,
-
- Jos aka jos@and.nl
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-